package com.distribution.common.web.handler;

import com.distribution.common.web.response.ResponseResult;
import com.distribution.common.web.response.ResponseUtils;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author test
 * @date 2022年01月04日 13:50
 */

@Component
public class RequestAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
        ResponseUtils.send(httpServletResponse,new ResponseResult(HttpStatus.FORBIDDEN.value(),"no permission"));
    }
}
